﻿using System;
using System.Collections.Generic;
using System.Linq;
using FineUI;
using SysManage.BLL;
using ZHDJ.Core.Util;
using ZHDJ.Data.DataCaching;
using ZHDJ.Data.Models.Common;

namespace SysManage.Module.Menu
{
    public partial class PartyModuleNavigationModuleEdit : PageBase
    {
        #region ViewPower

        /// <summary>
        /// 本页面的浏览权限，空字符串表示本页面不受权限控制
        /// </summary>
        public override string ViewPower
        {
            get
            {
                return "PartyModuleNavigationAdd";
            }
        }

        #endregion

        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            btnClose.OnClientClick = ActiveWindow.GetHideReference();
            string id = GetQueryIntValue("id");
            if (id != "")
            {
                PartyModuleNavigation current = DB.PartyModuleNavigations.Find(id);
                if (current == null)
                {
                    // 参数错误，首先弹出Alert对话框然后关闭弹出窗口
                    Alert.Show("参数错误！", String.Empty, ActiveWindow.GetHideReference());
                    return;
                }
                txtModule.Text = current.Module;
                txtPageName.Text = current.PageName;
                txtModule.Readonly = true;

            }
        }

        #endregion

        #region Events

        private void SaveJobTitle()
        {
            PartyModuleNavigation item;
            string id = GetQueryIntValue("id");
            if (id != "")
            {
                //更新
                 item = DB.PartyModuleNavigations.Find(id);
                if (item == null)
                {
                    Alert.Show("参数错误！", String.Empty);
                    return;
                }
               
            }
            else
            {
                var current = DB.SystemParameters.Find(this.txtModule.Text.Trim());
                if (current != null)
                {
                    Alert.Show("模块标识已存在，请重新输入！", String.Empty);
                    return;
                }
                item = new PartyModuleNavigation();
                item.ID = txtModule.Text;
                DB.PartyModuleNavigations.Add(item);
            }
           
            item.Module = txtModule.Text;
            item.PageName = txtPageName.Text;
            item.Enabled = true;
            DB.SaveChanges();
            PartyModuleNavigationCaching.Clean();
        }

        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            SaveJobTitle();
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #endregion

    }
}
